"""
    变量的类型注解
    类型注解并不会限制必须为什么类型，是为了更方便的代码提示
"""
# 基础数据类型注解
import json
import random
from typing import Union

oo1: int = 10
oo2: str = 'hello world'
oo3: bool = True


# 类对象类型注解
class Student:
    pass


stu: Student = Student()

# 基础容器类型注解
# my_list: list = [1, 2, 3]
# my_tuple: tuple = (2, 3, 4)
# my_dict: dict = {"name": "suntao"}
# 容器类型详细注解
my_list: list[int] = [1, 2, 3]
my_tuple: tuple[int, str, bool] = (2, "3", True)
my_dict: dict[str, int] = {"name": 33}

# 在注释中进行类型注解
var_1 = random.randint(1, 10)  # type: int
var_2 = json.loads('{"name": "lisi"}')  # type:dict[str,str]

"""
演示对函数（方法）进行类型注解
"""


# 对形参进行类型注解
def add(x: int, y: int):
    return x + y


# 对返回值进行类型注解
def func(data: list) -> list:
    return data


"""
演示Union联合类型注解
"""
# 使用Union类型，必须先导包

# 表示可以为int类型也可以为str类型
my_list1: list[Union[int, str]] = [1, 2, "itheima", "itcast"]
my_dict1: dict[str, Union[str, int]] = {'name': "周杰伦", 'age': 18}


def func(data: Union[int, str]) -> Union[int, str]:
    pass


print(func(1))


def func():
    return 10


var_3 = func()  # type: int
var_4: int = 123
